package mop.model.task.filter;

import java.util.LinkedList;
import java.util.List;

import mop.model.task.TaskInterface;
import mop.model.task.tasktype.TaskType;
import mop.util.filter.Filter;
/**
 * Filter based on task types
 * @author MOP Team 7
 * 
 * @invar type != null
 *
 */
public class TaskTypeFilter implements Filter<TaskInterface>{
	
	/**
	 * Constructor
	 * @param type	Type we want to filter
	 * @effect Type is set
	 * 	|setType(type)
	 */
	public TaskTypeFilter(TaskType type){
		setType(type);
	}
	
	/**
	 * The type we want to filter 
	 */
	private TaskType type;
	
	/**
	 * Set type value we want to filter
	 * @param type
	 * @post Type  is set to given value
	 * 	|getType() == type
	 */
	public void setType(TaskType type){
		if(type == null)
			throw new IllegalArgumentException("Task type is not set in task type filter");
		
		this.type = type;
	}
	
	/**
	 * Return type filter value
	 * @return this.type
	 */
	public TaskType getType(){
		return this.type;
	}
	
	/**
	 * @see Filter#filter(List)
	 */
	@Override
	public List<TaskInterface> filter(List<TaskInterface> list) {
		List<TaskInterface> copy = new LinkedList<TaskInterface>();
		
		for(TaskInterface t : list)
		{
			if(t.getTaskType().equals(getType()))  //TODO
				copy.add(t);
		}
			
		return copy;
	}
	
}
